import QtQuick 1.0

Item {
    id: root
    property real heading: phoneModel.heading()
    property real bearing: phoneModel.bearing()
    property bool headingup: true

    width: parent.width
    height: parent.height
    opacity: parent.opacity

    signal clicked()

    MouseArea {
        id: mouseArea
        anchors.fill: parent
        onClicked: root.clicked()
    }

    Connections { target: phoneModel; onHeadingChanged: heading = phoneModel.heading() }
    //Connections { target: borisModel; onBearingChanged: bearing = borisModel.bearing() }

    function headingChanged() {
        heading = phoneModel.heading()
    }

    function bearingChanged() {
        bearing = phoneModel.bearing()
    }

    Image {
        source: "qrc:///images/directionarrow.svg"
        width: parent.width
        height: parent.height
        transform: Rotation {
            id: needle            
            origin.x: width/2
            origin.y: height/2
            angle: if (root.headingup) (root.bearing - root.heading) % 360; else root.bearing
            Behavior on angle {
                SpringAnimation {
                    spring: 1.4
                    damping: .15
                    modulus: 360                    
                }
            }
        }
    }
}
